//get items

let items = [];
const url = 'http://192.168.239.166:8080/',
      $ul = document.querySelector('ul'),
      $form = document.querySelector('form'),
      $item = document.querySelector('input[type="text"]');

function getItems() {
  fetch(url).then(res => {
    res.text().then(text => {
      console.log(text)
      items = JSON.parse(text);

      const dom = items.map(item => `<li>${item.value}</li>`).join('');
      $ul.innerHTML = dom;
    });
  });
  
};

$form.onsubmit = (e) => {
  e.preventDefault();
  console.log($item.value);

  fetch(url,{method:'POST',body:`item=${$item.value}`}).then(res => {
    getItems();
  })
};


